<?php
// $Id$

/**
 * Controller_Admin_Userperiodrate 控制器
 */
class Controller_Admin_Userperiodrate extends Controller_Abstract
{
	function _format_appendSql()
	{
		if (isset($_SESSION['acct']))
		{
			if ($_SESSION['acct']['admin_id'] == -1 && $_SESSION['acct']['agent_id'] == -1)
			{
			//为管理
				$append = array();
			}else
			{
				$append['agent_id'] = Acct::_get_have_acctid($_SESSION['acct']['id'], $_SESSION['acct']['admin_id']);
		
			}
		}
		return $append;
	}	
	function actionIndex()
	{
        $this->union_table = Userperiodrate::meta();
        $this->lists($this->_format_appendSql());
        
        $cur_packageInfo = Ratepackage::find('id = ?',$this->_context->ratepackage_id)->getOne();
        $this->_view['packageInfo'] = $cur_packageInfo;
        
	}
	
	function actionadd()
	{
		$this->union_table = Userperiodrate::meta();
		//ini_set('allow_call_time_pass_reference', true); //开启引用？
		$handle = new helper_autoinsert($this->union_table);
		$form = new Form_userperiodrate_add(url($this->_context->controller_name.'/'.$this->_context->action_name));
		$result = $handle->add($form, 'id',$_GET);
		$agent_id = $this->_context->agent_id;
		$fParam = $this->_format_appendSql();
		if (isset($fParam['agent_id']) && !in_array($agent_id, $fParam['agent_id']))
		{
			exit('非法尝试');
		}
		if ($this->_context->isGET())
		{
			$result->element('rategroupid')->items = Rategroup::_get_arrayinfo($fParam); 
			$this->_view['form'] = $result;
			$this->_viewname = '../form/add';
		}else {
			Syslog::logs('编辑用户套餐内容:'.$this->_context->rategroupid);
			return call_user_func_array(array($this,$handle->status),array($result));
		}
	}
	function actiondel()
	{
		Syslog::logs('删除用户套餐内容:'.$this->_context->ids);
		$this->union_table = Periodrate::meta();
		$this->delete(array_merge($this->_format_appendSql(),array('id'=>$this->_context->ids)));
	}
	
}


